import Vue from 'vue';
import Router from 'vue-router';

const Page404 = r => require.ensure([], () => r(require('@/pages/404/404')), '404');
const PageError = r => require.ensure([], () => r(require('@/pages/error/error')), 'error');
const Login = r => require.ensure([], () => r(require('@/pages/login/login')), 'login');
const ForgotPassword = r => require.ensure([], () => r(require('@/pages/forgot-password/forgot-password')), 'forgot-password');
const Main = r => require.ensure([], () => r(require('@/pages/main/main')), 'main');
const Dashbord = r => require.ensure([], () => r(require('@/pages/main/dashbord/dashbord')), 'dashbord');
const AccountSet = r => require.ensure([], () => r(require('@/pages/main/account/account-set')), 'account-set');
const SupplierPO = r => require.ensure([], () => r(require('@/pages/main/supplier-PO/supplier-PO')), 'supplier-PO');
const WaitToConfirm = r => require.ensure([], () => r(require('@/pages/main/supplier-PO/wait-to-confirm/wait-to-confirm')), 'wait-to-confirm');
const Confirmed = r => require.ensure([], () => r(require('@/pages/main/supplier-PO/confirmed/confirmed')), 'confirmed');
const WaitToShipWH = r => require.ensure([], () => r(require('@/pages/main/supplier-PO/wait-to-ship/wait-to-ship-WH')), 'wait-to-ship-WH');
const WaitToShipCreateShipment = r => require.ensure([], () => r(require('@/pages/main/supplier-PO/wait-to-ship/create-shipment')), 'create-shipment');
const Shipped = r => require.ensure([], () => r(require('@/pages/main/supplier-PO/shipped/shipped')), 'shipped');
const EditShipment = r => require.ensure([], () => r(require('@/pages/main/supplier-PO/shipped/edit-shipment')), 'edit-shipment');
const ShipmentDetail = r => require.ensure([], () => r(require('@/pages/main/supplier-PO/shipped/shipment-detail')), 'shipment-detail');

Vue.use(Router)

export default new Router({
  mode: 'history',
  routes: [
    {
      path: "*",
      redirect: "/404",
    },
    {
      path: '/',
      redirect: '/login',
    },
    {
      path: '/404',
      name: 'Page404',
      component: Page404
    },
    {
      path: '/error',
      name: 'PageError',
      component: PageError
    },
    {
      path: '/login',
      name: 'Login',
      component: Login
    },
    {
      path: '/forgot-password',
      name: 'ForgotPassword',
      component: ForgotPassword
    },
    {
      path: '/main',
      name: 'Main',
      component: Main,
      children: [
        {
          path: '/dashbord',
          name: 'Dashbord',
          component: Dashbord
        },
        {
          path: '/account-set',
          name: 'AccountSet',
          component: AccountSet
        },
        {
          path: '/supplier-PO',
          name: 'SupplierPO',
          component: SupplierPO,
          redirect: '/supplier-PO/wait-to-confirm',
          children: [
            {
              path: 'wait-to-confirm',
              name: 'WaitToConfirm',
              component: WaitToConfirm,
              meta: { keepAlive: false }
            },
            {
              path: 'confirmed',
              name: 'Confirmed',
              component: Confirmed,
              meta: { keepAlive: false }
            },
            {
              path: 'wait-to-ship-WH',
              name: 'WaitToShipWH',
              meta: { keepAlive: false },
              component: WaitToShipWH,
              children: [
                {path: 'create-shipment', name: 'WaitToShipCreateShipment', meta: { keepAlive: false }, component: WaitToShipCreateShipment}
              ]
            },
            {
              path: 'shipped',
              name: 'Shipped',
              component: Shipped,
              children: [
                {path: 'edit-shipment', name: 'EditShipment', component: EditShipment},
                {path: 'shipment-detail', name: 'ShipmentDetail', component: ShipmentDetail}
              ]
            }
          ]
        }
      ]
    }
  ]
})
